package fr.esiag.isidis.util;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;



public class Utils {

	public static int convertDateToInt(String date){
		Calendar calendar = Calendar.getInstance();
		SimpleDateFormat format = new SimpleDateFormat("dd/MM/yyyy HH:mm:ss");
		try {
			calendar.setTime(format.parse(date));
		} catch (ParseException e) {
		}
		
		int year       = calendar.get(Calendar.YEAR);
		int month      = calendar.get(Calendar.MONTH) + 1; // jan = 0 +1 = 1
		int day = calendar.get(Calendar.DAY_OF_MONTH); 
		
		//ex : 20141021 = date 21/10/2014
		return year*10000+month*100+day;
		
	}
	
	public static int convertHourToInt(String date){
		Calendar calendar = Calendar.getInstance();
		SimpleDateFormat format = new SimpleDateFormat("dd/MM/yyyy HH:mm:ss");
		try {
			calendar.setTime(format.parse(date));
		} catch (ParseException e) {
		}

		int hour  = calendar.get(Calendar.HOUR_OF_DAY); // 24 hour clock
		int minute     = calendar.get(Calendar.MINUTE);
	//	int second     = calendar.get(Calendar.SECOND);

		//ex : 1210 => 20h 10mn 00s
		return hour*60+minute;
	}
}
